package com.enjoyor.soa.traffic.server.tsms.dubbo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRouteDeviceDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboRltRouteDeviceService;
import com.enjoyor.soa.traffic.core.tsms.domain.RltRouteDevice;
import com.enjoyor.soa.traffic.core.tsms.domain.RltRoutePost;
import com.enjoyor.soa.traffic.core.tsms.service.IRltRouteDeviceService;
import com.enjoyor.soa.traffic.frame.support.util.DomainUtil;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboRltRouteDeviceService implements IDubboRltRouteDeviceService{

	@Autowired
	private IRltRouteDeviceService iRltRouteDeviceService;

	@Override
	public ResultPojo getRltRouteDevicePage(Page page, String rltDeviceId, String taskId, String routeId,
			String deviceId, String deviceName, String deviceTypeId) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo(iRltRouteDeviceService.getRltRouteDevicePage(page, rltDeviceId, taskId,
				routeId, deviceId, deviceName, deviceTypeId));
		return resultPojo;
	}

	@Override
	public ResultPojo getRltRouteDeviceList(String rltDeviceId, String taskId, String routeId, String deviceId,
			String deviceName, String deviceTypeId) {
		// TODO Auto-generated method stub
		List<RltRouteDevice> list = iRltRouteDeviceService.getRltRouteDeviceList(rltDeviceId, taskId, routeId, deviceId,
				deviceName, deviceTypeId);
		ResultPojo resultPojo = new ResultPojo(ReflectHelper.listToList(list, RltRouteDeviceDto.class));
		return resultPojo;
	}

	@Override
	public ResultPojo insertRltRouteDevice(RltRouteDeviceDto rltRouteDeviceDto, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo  =  new ResultPojo();
		RltRouteDevice rltRouteDevice = ReflectHelper.beanToBean(rltRouteDeviceDto, RltRouteDevice.class);
		Boolean flag = iRltRouteDeviceService.insertRltRouteDevice(rltRouteDevice,personName);
		if(flag) {
			resultPojo = new ResultPojo("添加关联设备成功！");
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "设备类型错误！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo editRltRouteDevice(RltRouteDeviceDto rltRouteDeviceDto, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo  =  new ResultPojo();
		RltRouteDevice rltRouteDevice = ReflectHelper.beanToBean(rltRouteDeviceDto, RltRouteDevice.class);
		iRltRouteDeviceService.updateRltRouteDevice(rltRouteDevice,personName);
		return resultPojo;
	}

	@Override
	public ResultPojo deleteRltRouteDevice(String rltDeviceId, String personName) {
		// TODO Auto-generated method stub
		iRltRouteDeviceService.deleteRltRouteDevice(rltDeviceId,personName);
		return new ResultPojo();
	}

	@Override
	public ResultPojo rltRouteDeviceList(List<RltRouteDeviceDto> list, String taskId, String routeId,
			String deviceTypeId, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo  =  new ResultPojo();
		List<RltRouteDevice> listDevice = DomainUtil.merge2ListJson(list, RltRouteDevice.class);
		Boolean flag = iRltRouteDeviceService.rltRouteDeviceList(listDevice, taskId, routeId, deviceTypeId, personName);
		if(flag) {
			resultPojo = new ResultPojo("线路关联设备成功！");
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "设备类型错误！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo replaceRouteDevice(RltRouteDeviceDto rltRouteDeviceDto, String rltDeviceId, String personName) {
		// TODO Auto-generated method stub
		iRltRouteDeviceService.replaceRouteDevice(ReflectHelper.beanToBean(rltRouteDeviceDto, RltRouteDevice.class), rltDeviceId, personName);
		return new ResultPojo();
	}

}
